package org.jgs1904.chanmufeng;

/**
 * 静态内部类实现单例
 *
 * @author: 默苍璃
 * @date: 2024-07-01 11:30
 */
public class LazyStaticInnerClassSingleton {

    private LazyStaticInnerClassSingleton() {
        if (LazyHolder.LAZY != null) {
            throw new RuntimeException("实例被重复创建");
        }
    }

    public static final LazyStaticInnerClassSingleton getInstance() {
        return LazyHolder.LAZY;
    }

    // 静态内部类，未被使用时，是不会被加载的
    private static class LazyHolder {
        private static final LazyStaticInnerClassSingleton LAZY = new LazyStaticInnerClassSingleton();
    }

}
